/*
 * @Description: 添加任务
 * @Author: Zzt
 * @Date: 2022-08-09 14:59:01
 * @LastEditTime: 2022-08-09 16:16:41
 */

import { ICommonDialog } from '@/interfaces/global';
import { Button, Checkbox, Form, Input, Modal, Radio } from 'antd';
import { FC, useState } from 'react';
import { useTaskCronEContext } from '../../contexts/TaskCronEContext';
import FormItem from './common/FormItem';

interface IAddPlanDialogProps extends ICommonDialog {}
const AddPlan: FC<IAddPlanDialogProps> = (props) => {
  // const { visible, onClose };
  const [form] = Form.useForm();
  const { AddPlan } = useTaskCronEContext();
  const [isModalVisible, setIsModalVisible] = useState(false);
  const onFinish = (values: any) => {
    values.id = Date.now() + '';
    console.log(values);
    AddPlan(values);
    setIsModalVisible(false);
  };

  const onFinishFailed = (errorInfo: any) => {
    console.log('Failed:', errorInfo);
  };
  const showModal = () => {
    setIsModalVisible(true);
  };

  const handleOk = () => {
    form.submit();
  };

  const handleCancel = () => {
    setIsModalVisible(false);
  };
  return (
    <div>
      <Button onClick={showModal}>添加任务</Button>
      <Modal
        title="新增任务"
        visible={isModalVisible}
        onOk={handleOk}
        onCancel={handleCancel}
        destroyOnClose
        footer={[
          <Button key="back" onClick={handleCancel}>
            取消
          </Button>,
          <Button key="submit" type="primary" onClick={handleOk}>
            保存
          </Button>
        ]}
      >
        <Form
          form={form}
          labelCol={{ span: 5 }}
          wrapperCol={{ span: 20 }}
          onFinish={onFinish}
          onFinishFailed={onFinishFailed}
        >
          <FormItem />
        </Form>
      </Modal>
    </div>
  );
};
export default AddPlan;
